package com.gd.iot.energy.service.dailymanage.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gd.iot.energy.code.ResponseCode;
import com.gd.iot.energy.consts.SystemConsts;
import com.gd.iot.energy.dao.dailymanage.OperationfeeChargePOMapper;
import com.gd.iot.energy.exception.MyException;
import com.gd.iot.energy.po.dailymanage.OperationfeeChargePO;
import com.gd.iot.energy.pojo.common.vo.ColumnVO;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.dailymanage.dto.OperationfeeChargeBookDTO;
import com.gd.iot.energy.pojo.dailymanage.dto.OperationfeeChargeDTO;
import com.gd.iot.energy.pojo.dailymanage.dto.OperationfeeChargeQueryDTO;
import com.gd.iot.energy.pojo.dailymanage.dto.OperationfeeInvoiceDTO;
import com.gd.iot.energy.pojo.dailymanage.vo.ChargeBookPageVO;
import com.gd.iot.energy.pojo.dailymanage.vo.ChargeQueryPageVO;
import com.gd.iot.energy.pojo.dailymanage.vo.ChargeStatisticsPageVO;
import com.gd.iot.energy.pojo.dailymanage.vo.InvoicePageVO;
import com.gd.iot.energy.pojo.superadmin.dto.AdminDTO;
import com.gd.iot.energy.pojo.systemadmin.vo.AreaOrganizationVO;
import com.gd.iot.energy.service.dailymanage.OperationfeeChargeService;
import com.gd.iot.energy.service.systemadmin.AreaOrganizationService;
import com.gd.iot.energy.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 收费记录
 *
 * @author kris
 * @date Created at 8:27 上午 2020/8/8
 */
@Service
public class OperationfeeChargeServiceImpl extends ServiceImpl<OperationfeeChargePOMapper, OperationfeeChargePO> implements OperationfeeChargeService {

    @Resource
    private OperationfeeChargePOMapper operationfeeChargePOMapper;

    @Autowired
    private AreaOrganizationService areaOrganizationService;

    /**
     * 收费统计表头配置文件
     */
    private static final String CHARGE_STATISTICS_LIST_COLUMN_FILE_NAME = "dailymanage/charge_statistics_list.column";

    /**
     * 收费查询表头配置文件
     */
    private static final String CHARGE_QUERY_LIST_COLUMN_FILE_NAME = "dailymanage/charge_query_list.column";

    /**
     * 退费查询表头配置文件
     */
    private static final String REFUND_QUERY_LIST_COLUMN_FILE_NAME = "dailymanage/refund_query_list.column";

    /**
     * 收费台账表头配置文件
     */
    private static final String CHARGE_BOOK_LIST_COLUMN_FILE_NAME = "dailymanage/charge_book_list.column";

    /**
     * 开票管理表头配置文件
     */
    private static final String INVOICE_LIST_COLUMN_FILE_NAME = "dailymanage/invoice_list.column";

    /**
     * 收费记录
     *
     * @param operatingfeeSettlementTypeEnum 缴费方式
     * @param fee                            缴费金额
     * @param operatingfeePaywayEnum         支付方式
     * @param energyType                     表类型
     * @param chargeType                     收费类型（退费、收费等）
     * @param customerFee                    余额
     * @param areaArchiveId                  关联档案
     * @param receNumber                     收据编号
     */
    @Override
    public void saveOperationfeeCharge(SystemConsts.OperatingfeeSettlementTypeEnum operatingfeeSettlementTypeEnum,
                                       BigDecimal fee, SystemConsts.OperatingfeePaywayEnum operatingfeePaywayEnum,
                                       Integer energyType, SystemConsts.ChargeType chargeType, BigDecimal customerFee,
                                       Long areaArchiveId, String receNumber) {
        OperationfeeChargePO operationfeeChargePO = new OperationfeeChargePO();
        operationfeeChargePO.setPayTime(new Date());
        operationfeeChargePO.setCreateDate(new Date());
        operationfeeChargePO.setModifyDate(new Date());
        operationfeeChargePO.setPayway(operatingfeePaywayEnum.value);
        operationfeeChargePO.setPaychannel(SystemConsts.OperatingfeePaychannelEnum.WUYE.value);
        operationfeeChargePO.setChargeType(chargeType.value);
        operationfeeChargePO.setYuer(customerFee);
        operationfeeChargePO.setPaystate(SystemConsts.PayState.SUCCESS.value);
        operationfeeChargePO.setOperatingfeeSettlementType(operatingfeeSettlementTypeEnum.value);
        operationfeeChargePO.setHasInvoice(SystemConsts.InvoiceStatus.NO.value);
        operationfeeChargePO.setIsDel(SystemConsts.BooleanEnum.FALSE.value);
        operationfeeChargePO.setFee(fee);
        operationfeeChargePO.setEnergyType(energyType);
        operationfeeChargePO.setReceNumber(receNumber);
        operationfeeChargePO.setAreaarchives(areaArchiveId);
        AdminDTO userInfo = CurrentUserUtil.getUserInfo();
        operationfeeChargePO.setOperatorId(userInfo == null ? null : userInfo.getId());
        operationfeeChargePOMapper.insert(operationfeeChargePO);
    }

    @Override
    public PageVO<ChargeStatisticsPageVO> getChargeStatisticsPageVO(Integer operatorId, String cycle, String date, Integer areaId,
                                                                    Integer payway, Integer paychannel,
                                                                    Integer pageSize, Integer pageNum,
                                                                    String orderColumn, String orderType) {
        IPage<OperationfeeChargeDTO> page = new Page<>(pageNum, pageSize);
        QueryWrapper<OperationfeeChargeDTO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.is_del", SystemConsts.BooleanEnum.FALSE.value);
        queryWrapper.eq("b.is_del", SystemConsts.BooleanEnum.FALSE.value);
        queryWrapper.eq("c.is_del", SystemConsts.BooleanEnum.FALSE.value);
        queryWrapper.eq("a.energy_type", SystemConsts.EnergyTypeEnum.WATER.value);
        queryWrapper.eq("b.energy_type", SystemConsts.EnergyTypeEnum.WATER.value);
        queryWrapper.eq("c.energy_type", SystemConsts.EnergyTypeEnum.WATER.value);
        List<String> dates = CustomDateUtil.dataFormatCycle(cycle, date);
        if (dates.get(0) != null && dates.get(1) != null) {
            queryWrapper.between("a.pay_time", dates.get(0), dates.get(1));
        }
        if (operatorId != null) {
            queryWrapper.eq("a.operator_id", operatorId);
        }
        if (payway != null) {
            queryWrapper.eq("a.payway", payway);
        }
        if (paychannel != null) {
            queryWrapper.eq("a.paychannel", paychannel);
        }
        queryWrapper.eq("charge_type", SystemConsts.ChargeType.pay);
        queryWrapper.eq("paystate", SystemConsts.YesOrNoEnum.YES.value);
        if (areaId != null) {
            List<Long> allChildAreaIds = areaOrganizationService.getAllChildAreaIds(areaId);
            if (CollUtil.isNotEmpty(allChildAreaIds)) {
                queryWrapper.in("b.measure_area_org", allChildAreaIds);
            }
        }

        IPage<OperationfeeChargeDTO> operationfeeChargeDTOPage = operationfeeChargePOMapper.selectCustomPage(page, queryWrapper);
        PageVO<ChargeStatisticsPageVO> pageVO = new PageVO<>();
        pageVO.setPageSize(pageSize);
        pageVO.setPageNum(pageNum);
        List<ChargeStatisticsPageVO> chargeStatisticsPageVOS = convertToPageVOList(operationfeeChargeDTOPage.getRecords(), dates);
        pageVO.setData(chargeStatisticsPageVOS);
        pageVO.setTotal(operationfeeChargeDTOPage.getTotal());
        pageVO.setPages(operationfeeChargeDTOPage.getPages());

        //表头
        List<ColumnVO> columns = CustomColumnUtil.getColumn(CHARGE_STATISTICS_LIST_COLUMN_FILE_NAME);
        pageVO.setColumns(columns);
        return pageVO;
    }

    @Override
    public void exportChargeStatisticsExce(Integer operatorId, String cycle, String date, Integer areaId, Integer payway, Integer paychannel, String orderColumn, String orderType) {
        PageVO<ChargeStatisticsPageVO> chargeListPageVO = getChargeStatisticsPageVO(operatorId, cycle, date,
                areaId, payway, paychannel, Integer.MAX_VALUE, 1, orderColumn, orderType);
        String fileName = "Charge_Statistics_" +  DateUtil.current(false);
        String file = CustomExcelOperateUtil.exportExcel(SystemConsts.TEMP_FILE_PATH, fileName,
                chargeListPageVO.getColumns(), chargeListPageVO.getData());
        ResponseUtil.download(file, fileName + SystemConsts.EXCEL_SUFFIX);
    }

    @Override
    public PageVO<ChargeQueryPageVO> getChargeListPageVO(SystemConsts.ChargeType chargeType,
                                                         String customerSerialnumber,
                                                         String customerName, String cycle,
                                                         String date, Integer areaId,
                                                         Integer payway, Integer paychannel,
                                                         Integer pageSize, Integer pageNum,
                                                         String orderColumn, String orderType) {
        PageVO<ChargeQueryPageVO> pageVO = getChargeOrRefundQueryPageVO(chargeType,
                customerSerialnumber, customerName, cycle, date, areaId, payway, paychannel,
                pageSize, pageNum, orderColumn, orderType, chargeType);
        return pageVO;
    }

    /**
     * 收费or退费记录 分页
     *
     *
     * @param type
     * @param customerSerialnumber
     * @param customerName
     * @param cycle
     * @param date
     * @param areaId
     * @param payway
     * @param paychannel
     * @param pageSize
     * @param pageNum
     * @param orderColumn
     * @param orderType
     * @return
     */
    private PageVO<ChargeQueryPageVO> getChargeOrRefundQueryPageVO(SystemConsts.ChargeType type, String customerSerialnumber, String customerName,
                                                                   String cycle, String date, Integer areaId, Integer payway,
                                                                   Integer paychannel, Integer pageSize, Integer pageNum,
                                                                   String orderColumn, String orderType, SystemConsts.ChargeType chargeType) {
        IPage<OperationfeeChargeQueryDTO> page = new Page<>(pageNum, pageSize);
        QueryWrapper<OperationfeeChargeDTO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.is_del", SystemConsts.BooleanEnum.FALSE.value);
        queryWrapper.eq("b.is_del", SystemConsts.BooleanEnum.FALSE.value);
        queryWrapper.eq("a.energy_type", SystemConsts.EnergyTypeEnum.WATER.value);
        queryWrapper.eq("b.energy_type", SystemConsts.EnergyTypeEnum.WATER.value);
        List<String> dates = CustomDateUtil.dataFormatCycle(cycle, date);
        if (dates.get(0) != null && dates.get(1) != null) {
            queryWrapper.between("a.pay_time", dates.get(0), dates.get(1));
        }
        if (customerSerialnumber != null) {
            queryWrapper.like("b.customer_serialnumber", customerSerialnumber.trim());
        }
        if (customerName != null) {
            queryWrapper.like("b.customer_name", customerName.trim());
        }
        if (payway != null) {
            queryWrapper.eq("a.payway", payway);
        }
        if (paychannel != null) {
            queryWrapper.eq("a.paychannel", paychannel);
        }
        queryWrapper.eq("charge_type", chargeType.value);
        queryWrapper.eq("paystate", SystemConsts.YesOrNoEnum.YES.value);
        if (areaId != null) {
            List<Long> allChildAreaIds = areaOrganizationService.getAllChildAreaIds(areaId);
            if (CollUtil.isNotEmpty(allChildAreaIds)) {
                queryWrapper.in("b.measure_area_org", allChildAreaIds);
            }
        }
        if (StrUtil.isNotBlank(orderColumn) && StrUtil.isNotBlank(orderType)) {
            orderColumn = CustomStrUtil.humpToLine(orderColumn);
            queryWrapper.orderBy(true, orderType.equals(SystemConsts.OrderType.ASC.value), orderColumn);
        }

        IPage<OperationfeeChargeQueryDTO> operationfeeChargeQueryDTOPage = operationfeeChargePOMapper.selectCustomQueryPage(page, queryWrapper);
        PageVO<ChargeQueryPageVO> pageVO = new PageVO<>();
        pageVO.setPageSize(pageSize);
        pageVO.setPageNum(pageNum);
        List<ChargeQueryPageVO> chargeQueryPageVOS = convertQueryDTOToPageVOList(operationfeeChargeQueryDTOPage.getRecords());
        pageVO.setData(chargeQueryPageVOS);
        pageVO.setTotal(operationfeeChargeQueryDTOPage.getTotal());
        pageVO.setPages(operationfeeChargeQueryDTOPage.getPages());

        //表头
        List<ColumnVO> columns = CustomColumnUtil.getColumn(chargeType.equals(SystemConsts.ChargeType.pay)
                ? CHARGE_QUERY_LIST_COLUMN_FILE_NAME
                : REFUND_QUERY_LIST_COLUMN_FILE_NAME);
        pageVO.setColumns(columns);
        return pageVO;
    }

    @Override
    public void exportChargeListExcel(SystemConsts.ChargeType chargeType,
                                      String customerSerialnumber, String customerName,
                                      String cycle, String date, Integer areaId, Integer payway,
                                      Integer paychannel, String orderColumn, String orderType) {
        PageVO<ChargeQueryPageVO> chargeListPageVO = getChargeListPageVO(chargeType, customerSerialnumber, customerName, cycle, date,
                areaId, payway, paychannel, Integer.MAX_VALUE, 1, orderColumn, orderType);
        String fileName = "Fee_List_" + DateUtil.current(false);
        String file = CustomExcelOperateUtil.exportExcel(SystemConsts.TEMP_FILE_PATH, fileName,
                chargeListPageVO.getColumns(), chargeListPageVO.getData());
        ResponseUtil.download(file, fileName + SystemConsts.EXCEL_SUFFIX);
    }

    @Override
    public PageVO<ChargeBookPageVO> getChargeBookPageVO(String cycle, String date, Integer areaId, Integer pageSize, Integer pageNum) {
        IPage<OperationfeeChargeBookDTO> page = new Page<>(pageNum, pageSize);
        QueryWrapper<OperationfeeChargeBookDTO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.is_del", SystemConsts.BooleanEnum.FALSE.value);
        queryWrapper.eq("a.energy_type", SystemConsts.EnergyTypeEnum.WATER.value);
        if (areaId != null) {
            List<Long> allChildAreaIds = areaOrganizationService.getAllChildAreaIds(areaId);
            if (CollUtil.isNotEmpty(allChildAreaIds)) {
                queryWrapper.in("a.measure_area_org", allChildAreaIds);
            }
        }
        List<String> dates = CustomDateUtil.dataFormatCycle(cycle, date);
        IPage<OperationfeeChargeBookDTO> chargeBookDTOPage = operationfeeChargePOMapper.selectCustomChargeBookPage(page, queryWrapper, dates.get(0), dates.get(1));
        PageVO<ChargeBookPageVO> pageVO = new PageVO<>();
        pageVO.setPageSize(pageSize);
        pageVO.setPageNum(pageNum);
        List<ChargeBookPageVO> chargeBookPageVOS = convertBookDTOToPageVOList(chargeBookDTOPage.getRecords(), dates);
        pageVO.setData(chargeBookPageVOS);
        pageVO.setTotal(chargeBookDTOPage.getTotal());
        pageVO.setPages(chargeBookDTOPage.getPages());

        //表头
        List<ColumnVO> columns = CustomColumnUtil.getColumn(CHARGE_BOOK_LIST_COLUMN_FILE_NAME);
        pageVO.setColumns(columns);
        return pageVO;
    }

    @Override
    public void exportChargeBookExcel(String cycle, String date, Integer areaId) {
        PageVO<ChargeBookPageVO> chargeListPageVO = getChargeBookPageVO(cycle, date,
                areaId, Integer.MAX_VALUE, 1);
        String fileName = "Charge_Book_List_" +  DateUtil.current(false);
        String file = CustomExcelOperateUtil.exportExcel(SystemConsts.TEMP_FILE_PATH, fileName,
                chargeListPageVO.getColumns(), chargeListPageVO.getData());
        ResponseUtil.download(file, fileName + SystemConsts.EXCEL_SUFFIX);
    }

    @Override
    public PageVO<InvoicePageVO> getInvoicePageVO(String customerSerialnumber, String customerName,
                                                  Integer hasInvoice, String beginDate, String endDate,
                                                  Integer pageSize, Integer pageNum, String orderColumn,
                                                  String orderType) {
        QueryWrapper<OperationfeeInvoiceDTO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.is_del", SystemConsts.BooleanEnum.FALSE.value);
        queryWrapper.eq("b.is_del", SystemConsts.BooleanEnum.FALSE.value);
        queryWrapper.eq("a.energy_type", SystemConsts.EnergyTypeEnum.WATER.value);
        queryWrapper.eq("b.energy_type", SystemConsts.EnergyTypeEnum.WATER.value);

        if (StrUtil.isNotBlank(beginDate)) {
            queryWrapper.ge(true, "a.pay_time", DateUtil.beginOfDay(DateUtil.parseDate(beginDate)));
        }
        if (StrUtil.isNotBlank(endDate)) {
            queryWrapper.le(true, "a.pay_time", DateUtil.endOfDay(DateUtil.parseDate(endDate)));
        }
        if (hasInvoice != null) {
            queryWrapper.eq("a.has_invoice", hasInvoice);
        }
        if (customerSerialnumber != null) {
            queryWrapper.like("b.customer_serialnumber", customerSerialnumber.trim());
        }
        if (customerName != null) {
            queryWrapper.like("b.customer_name", customerName.trim());
        }
        List<AreaOrganizationVO> areaOrganizationVOs = areaOrganizationService.getAreaOrganizationVOs();
        if (!areaOrganizationVOs.isEmpty()) {
            queryWrapper.in("b.measure_area_org", areaOrganizationVOs.stream().map(AreaOrganizationVO::getId).collect(Collectors.toList()));
        }
        queryWrapper.eq("paystate", SystemConsts.YesOrNoEnum.YES.value);
        queryWrapper.eq("charge_type", SystemConsts.ChargeType.pay.value);

        if (StrUtil.isNotBlank(orderColumn) && StrUtil.isNotBlank(orderType)) {
            orderColumn = CustomStrUtil.humpToLine(orderColumn);
            queryWrapper.orderBy(true, orderType.equals(SystemConsts.OrderType.ASC.value), orderColumn);
        }

        IPage<OperationfeeInvoiceDTO> page = new Page<>(pageNum, pageSize);
        IPage<OperationfeeInvoiceDTO> invoiceDTOPage = operationfeeChargePOMapper.selectInvoicePage(page, queryWrapper);
        PageVO<InvoicePageVO> pageVO = new PageVO<>();
        pageVO.setPageSize(pageSize);
        pageVO.setPageNum(pageNum);
        List<InvoicePageVO> invoicePageVOS = convertInvoiceDTOToPageVOList(invoiceDTOPage.getRecords());
        pageVO.setData(invoicePageVOS);
        pageVO.setTotal(invoiceDTOPage.getTotal());
        pageVO.setPages(invoiceDTOPage.getPages());

        //表头
        List<ColumnVO> columns = CustomColumnUtil.getColumn(INVOICE_LIST_COLUMN_FILE_NAME);
        pageVO.setColumns(columns);
        return pageVO;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void invoice(List<Integer> ids) {
        if(ids.isEmpty()){
            throw new MyException(ResponseCode.PARAMETER_REQUIRED);
        }
        QueryWrapper<OperationfeeChargePO> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",ids);
        queryWrapper.eq("is_del", SystemConsts.BooleanEnum.FALSE.value);
        EnergyTypeUtil.injectEnergyTypeWrapper(queryWrapper);
        OperationfeeChargePO operationfeeChargePO = new OperationfeeChargePO();
        operationfeeChargePO.setHasInvoice(SystemConsts.InvoiceStatus.YES.value);
        operationfeeChargePOMapper.update(operationfeeChargePO,queryWrapper);
    }

    @Override
    public PageVO<InvoicePageVO> getInvoiceRecordPageVO(String customerSerialnumber, String customerName, String beginDate, String endDate, Integer pageSize, Integer pageNum) {
        return getInvoicePageVO(customerSerialnumber,customerName, SystemConsts.InvoiceStatus.YES.value,beginDate,endDate,pageSize,pageNum,"a.pay_time","desc");
    }

    /**
     * 开票dto转vo
     *
     * @param records
     * @return
     */
    private List<InvoicePageVO> convertInvoiceDTOToPageVOList(List<OperationfeeInvoiceDTO> records) {
        List<InvoicePageVO> res = new ArrayList<>(records.size());
        InvoicePageVO invoicePageVO;
        long i = 1;
        for (OperationfeeInvoiceDTO record : records) {
            invoicePageVO = new InvoicePageVO();
            invoicePageVO.setId(record.getId());
            invoicePageVO.setSerialNum(i);
            invoicePageVO.setCustomerSerialnumber(record.getCustomerSerialnumber());
            invoicePageVO.setCustomerName(record.getCustomerName());
            invoicePageVO.setReceNumber(record.getReceNumber());
            invoicePageVO.setOperator(record.getOperator());
            invoicePageVO.setPayTime(DateUtil.formatDate(record.getPayTime()));
            invoicePageVO.setHasInvoice(SystemConsts.InvoiceStatus.getValueNameByValue(record.getHasInvoice()));
            invoicePageVO.setPayway(SystemConsts.OperatingfeePaywayEnum.getNameByValue(record.getPayway()));
            invoicePageVO.setFee(record.getFee().setScale(2,BigDecimal.ROUND_UP).toPlainString());
            res.add(invoicePageVO);
            i++;
        }
        return res;
    }

    /**
     * 台账dto转vo
     *
     * @param records
     * @param dates
     * @return
     */
    private List<ChargeBookPageVO> convertBookDTOToPageVOList(List<OperationfeeChargeBookDTO> records, List<String> dates) {
        List<ChargeBookPageVO> res = new ArrayList<>(records.size());
        ChargeBookPageVO chargeBookPageVO;
        int i = 1;
        for (OperationfeeChargeBookDTO record : records) {
            chargeBookPageVO = new ChargeBookPageVO();
            chargeBookPageVO.setId(record.getId());
            chargeBookPageVO.setSerialNum(i);
            chargeBookPageVO.setCustomerName(record.getCustomerName());
            chargeBookPageVO.setCustomerPhone(record.getCustomerPhone());
            chargeBookPageVO.setCustomerSerialnumber(record.getCustomerSerialnumber());
            chargeBookPageVO.setRefundfee(record.getRefundfee() == null
                    ? SystemConsts.ZERO_2
                    : record.getRefundfee().setScale(2, RoundingMode.HALF_UP).toPlainString());
            chargeBookPageVO.setPayfee(record.getPayfee() == null
                    ? SystemConsts.ZERO_2
                    : record.getPayfee().setScale(2, RoundingMode.HALF_UP).toPlainString());
            chargeBookPageVO.setPay(record.getPay() == null
                    ? SystemConsts.ZERO_2
                    : record.getPay().setScale(2, RoundingMode.HALF_UP).toPlainString());
            if (dates.get(0) != null && dates.get(1) != null) {
                chargeBookPageVO.setStartTime(dates.get(0));
                chargeBookPageVO.setEndTime(dates.get(1));
            }
            res.add(chargeBookPageVO);
            i++;
        }
        return res;
    }

    /**
     * 收费查询dto转vo
     *
     * @param records
     * @return
     */
    private List<ChargeQueryPageVO> convertQueryDTOToPageVOList(List<OperationfeeChargeQueryDTO> records) {
        List<ChargeQueryPageVO> res = new ArrayList<>(records.size());
        ChargeQueryPageVO chargeQueryPageVO;
        int i = 1;
        for (OperationfeeChargeQueryDTO record : records) {
            chargeQueryPageVO = new ChargeQueryPageVO();
            chargeQueryPageVO.setId(record.getId());
            chargeQueryPageVO.setSerialNum(i);
            chargeQueryPageVO.setFee(record.getFee().setScale(2, RoundingMode.HALF_UP).toPlainString());
            chargeQueryPageVO.setReceNumber(record.getReceNumber());
            chargeQueryPageVO.setCustomerName(record.getCustomerName());
            chargeQueryPageVO.setCustomerSerialnumber(record.getCustomerSerialnumber());
            chargeQueryPageVO.setPayTime(DateUtil.formatDate(record.getPayTime()));
            chargeQueryPageVO.setPayway(SystemConsts.OperatingfeePaywayEnum.getNameByValue(record.getPayway()));
            res.add(chargeQueryPageVO);
            i++;
        }
        return res;
    }

    /**
     * 转vo
     *
     * @param records
     * @param dates
     * @return
     */
    private List<ChargeStatisticsPageVO> convertToPageVOList(List<OperationfeeChargeDTO> records, List<String> dates) {
        List<ChargeStatisticsPageVO> res = new ArrayList<>(records.size());
        ChargeStatisticsPageVO chargeStatisticsPageVO;
        int i = 1;
        for (OperationfeeChargeDTO record : records) {
            chargeStatisticsPageVO = new ChargeStatisticsPageVO();
            chargeStatisticsPageVO.setSerialNum(i);
            chargeStatisticsPageVO.setId(record.getId());
            chargeStatisticsPageVO.setAreaName(record.getAreaName());
            chargeStatisticsPageVO.setFee(record.getFee().setScale(2, RoundingMode.HALF_UP).toPlainString());
            chargeStatisticsPageVO.setPayway(SystemConsts.OperatingfeePaywayEnum.getNameByValue(record.getPayway()));
            if (dates.get(0) != null && dates.get(1) != null) {
                chargeStatisticsPageVO.setStartTime(dates.get(0));
                chargeStatisticsPageVO.setEndTime(dates.get(1));
            }
            res.add(chargeStatisticsPageVO);
            i++;
        }
        return res;
    }
}
